package cn.com.bluemoon.design.strategy;

import cn.com.bluemoon.daps.common.enums.StandardAuditStatus;

import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;


/**
 * @author Jarod.Kong
 * @date 2021/1/11 17:27
 */
public class StrategyClient {
    private static final ConcurrentHashMap<Class<? extends AuditStatusChange>, AuditStatusChange>
            auditStatusMap = new ConcurrentHashMap<>();

    static {
        ServiceLoader<AuditStatusChange> load = ServiceLoader.load(AuditStatusChange.class);
        for (AuditStatusChange auditStatus : load) {
            auditStatusMap.put(auditStatus.getClz(), auditStatus);
        }
        System.out.println(load);
    }

    public static void main(String[] args) {
        String audit = new StrategyClient().audit(WaitAuditChange.class, "1", null,
                null, null);
        System.out.println(audit);
    }

    public String audit(Class<? extends AuditStatusChange> clz,
                         String auditId,
                         StandardAuditStatus targetAuditStatus,
                         Integer modifyTypeDefine,
                         String nextStandardId) {
        AuditStatusChange statusChange = auditStatusMap.get(clz);
        if (statusChange != null) {
            String change = statusChange.change(auditId, targetAuditStatus, modifyTypeDefine, nextStandardId);
            return change;
        }
        return null;
    }

}
